package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2019/2/22 11:35
 * @description
 */
public class Code172 {
    public static void main(String[] args) {
        System.out.println(new Code172().trailingZeroes(50));
    }

    //public int trailingZeroes(int n) {
    //    int count = 0;
    //    long sum = 1;
    //    for (int i = 2; i <= n; i++) {
    //        sum *= i;
    //        if (sum % 10 == 0) {
    //            while (sum % 10 == 0) {
    //                sum /= 10;
    //                count++;
    //            }
    //        }
    //        if (sum > 100000000) {
    //            sum %= 100000000;
    //        }
    //    }
    //    return count;
    //}

    public int trailingZeroes(int n) {
        int count = 0;
        for (long i = 5; i <= n; i += 5) {
            long k = i;
            if (k % 5 == 0) {
                while (k % 5 == 0) {
                    k /= 5;
                    count++;
                }
            }
        }
        return count;
    }
}
